﻿using UnityEngine;
using UnityEngine.UI;

namespace UFrame
{
    /// <summary>
    /// 冒泡文字
    /// </summary>
    public class UIPopTool
    {
        public static int fontSize = 45;
        
        #region PopText

        public static void ShowPop(string text)
        {
            //ShowUI(EUI.UIPopTips, text);
            EventMa.Notify<UIPopTextArgs>(UIPopTextArgs.EventId, new UIPopTextArgs()
            {
                text = text
            });
        }

        public static void ShowBulletPop(string text)
        {
            //ShowUI(EUI.UIPopTips, text);
            EventMa.Notify<UIPopTextArgs>(UIPopTextArgs.EventId, new UIPopTextArgs()
            {
                text = text,
                isBulletPop = true,
            });
        }
        
        #endregion
        
        //内置
        public static void SystemPop(string text)
        {
            var canvas = GameObject.FindObjectOfType<Canvas>();
            
            GameObject go = new GameObject();
            var textCom =  go.AddComponent<Text>();
            textCom.text = text;
            go.transform.SetParent(canvas.transform);
            var rect = go.GetComponent<RectTransform>();
            go.AddComponent<USystemPop>();
            //go.transform.position
            rect.anchoredPosition = Vector3.zero;

            Font f = Resources.GetBuiltinResource<Font>("Arial.ttf");
            textCom.font = f;
            textCom.fontSize = fontSize;
            rect.sizeDelta = new Vector2(450,450);
            textCom.alignment = TextAnchor.MiddleCenter;
            textCom.color = Color.black;
            textCom.raycastTarget = false;
            textCom.name = "POP";
        }

    }
}